package com.fecean.aabbc.netty.client.init;

import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;

/**
 * ClientChannelCache
 *
 * @author: chenfenghai
 * @version: 1.0
 * @date: 2020-02-25 13:43
 * @blame Team
 */
@Component
public class ClientChannel {

    private Channel clientChannel = null;

    public void saveClientChannel(Channel channel){
        clientChannel = channel;
    }

    public Channel getClientChannel(){
        return clientChannel;
    }

    public Channel removeClientChannel(){
        return clientChannel = null;
    }

    public ChannelFuture writeAndFlush(Object object){
        if(clientChannel == null){
            return null;
        }
        return clientChannel.writeAndFlush(object);
    }
}
